/*************************************************************
 * 
 * CopyRight(c)2007, http://www.moorwind.com/
 * email:ezhung@gmail.com
 * for free, but a email permission would be nice
 * 
 ************************************************************/
package kono.utils.search
{
	import flash.accessibility.Accessibility;
	
	public class Search
	{
		public function Search(){}
		
		public static function linearSearch(source:Array, target:*):Boolean
		{
			for(var i:uint = 0; i < source.length; i++)
			{
				if(source[i] == target)
					return true;
			}
			return false;
		}
		
		public static function binarySearch(source:Array, start:uint, size:uint, target:*):Boolean
		{
			if(size == 0)
				return false;
			else
			{
				var middle:uint = start + ( size >> 1 );
				if(target == source[middle])
					return true;
				else if(target < source[middle])
					return binarySearch(source, start, size >> 1, target);
				else
					return binarySearch(source, middle + 1, (size - 1) >> 1, target);
			}
		}
	}
}